{
LANG : PASCAL
PROB : fact4
}

program FACT4;
const
  fi = 'fact4.in';
  fo = 'fact4.out';
  nt : array[1..4] of integer = (1, 3, 7, 9);
var
  mu2, mu5 : array[0..100] of longint;
  s : array[1..4] of longint;
  n, log2, log5, res : longint;

function cal(n, k : longint) : longint;
var
  res : longint;
begin
  res := 0;
  while n > 0 do
  begin
    inc(res, n div k);
    n := n div k;
  end;
  cal := res;
end;

function getlog(n, k : longint) : longint;
var
  temp, log : longint;
begin
  log := 0;
  temp := 1;
  while temp < n do
  begin
    temp := temp * k;
    inc(log);
  end;
  getlog := log-1;
end;

procedure init;
var
  i : integer;
begin
  log2 := getlog(n, 2);
  mu2[0] := 1;
  for i := 1 to log2 do mu2[i] := mu2[i-1]*2;
  log5 := getlog(n, 5);
  mu5[0] := 1;
  for i := 1 to log5 do mu5[i] := mu5[i-1]*5;
end;

procedure process;
var
  i, j, k, i2, i5 : integer;
  temp, w : longint;
begin
  j := (cal(n, 2) - cal(n, 5) - 1) mod 4 + 1;
  res := 1;
  for i := 1 to j do res := (res*2) mod 10;

  for i2 := 0 to log2 do
    for i5 := 0 to getlog(n div mu2[i2], 5) do
    begin
      temp := mu2[i2]*mu5[i5];
      w := n div temp;
      for k := 1 to 4 do
      begin
        inc(s[k], w div 10);
        if w mod 10 >= nt[k] then inc(s[k]);
        s[k] := s[k] mod 4;
      end;
    end;

  for i := 1 to 4 do
    for j := 1 to s[i] do res := (res*nt[i]) mod 10;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(n);
  init;
  process;
  writeln(res);
  close(output);
  close(input);
end.